<?php
namespace Home\Controller;
use \Think\Controller;

class WritercenterController extends HomeController
{
    public function index()
    {   
        $uid=I('get.uid');
        // var_dump($uid);
        // $this->display('Zuoze/index');
        //    $this->display('Writercenter/index');
        // exit;
     
        $user  = M('user')->field('pwd',true)->where('id ='.$uid.'')->find();
         
        $article  =M('article')
                                ->where('user_id ='.$uid.' AND status = 1')
                                ->order('id desc')
                                ->select();
        // v($article);
        // $_SESSION['article']['count']=$count;
        $this->assign('user',$user);
       
        $this->assign('article',$article);
        $this->display('Writercenter/index');
    }

    public function dopost()
    {   
        // V($_POST);
        // V($_SESSION['user']);
        // exit;
        if($_SESSION['user']['id']==''){
            $_SESSION['url']=MODULE_NAME.'/'.CONTROLLER_NAME.'/index/'.uid.'/'.$_POST['writer_id'];
            // V($_SESSION);exit;
            $this->error('请先登录!',U('Login/login'));
        }
        if($_POST['writer_id'] =='' || $_POST['msg'] == ''){
            $this->error('内容不能为空!');
        }
        $writer_id=I('post.writer_id/d');
        // $writer_id = $_SESSION['user']['id'];
        $msg = $_POST['msg'];
        $user_id=$_SESSION['user']['id'];
        $time = time();
        $data=array('writer_id'=>$writer_id,'msg'=>$msg,'user_id'=>$user_id,'time'=>$time);

        $info = M('private_msg');
        $row=$info->add($data);


       if($row){
        $this->success('发送成功!');
       } else {
        $this->error('发送失败!');
       }
    }
    
}